package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.logic.pb.CrossRankPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross.group.CrossGroupProto;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.rank.CrossGroupUserMonthAbilityRankMgr;
import com.yanqu.road.server.manger.CrossUnionServerGroupMgr;
import com.yanqu.road.server.manger.ServerGroupMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.date.DateHelper;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.C_UNION_GROUP_USER_RANK_CHANGE, desc = "跨服分组排行数据变化")
public class CrossGroupUserRankChangeCmd extends CrossCommand {


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossGroupProto.CrossGroupRankChangeReqMsg reqMsg = CrossGroupProto.CrossGroupRankChangeReqMsg.parseFrom(packet.getBytes());
        int groupId = CrossUnionServerGroupMgr.getGroupIdByServerId(serverId);
        List<CrossUserRank> rankList = new ArrayList<>();
        for (CrossGroupProto.CrossGroupRankChangeMsg msg : reqMsg.getDataList()) {
            RankProto.RankTempMsg temMsg = msg.getData();
            int type = msg.getType();
            int bigType = msg.getBigRankType();
            CrossUserRank crossUserRank = CrossRankPb.parseCrossUserRank(type, temMsg, bigType);
            if (crossUserRank.getValue().compareTo(BigInteger.valueOf(Long.MIN_VALUE)) == 0) {
                continue;
            }
            rankList.add(crossUserRank);
        }
        CrossGroupUserMonthAbilityRankMgr.receiveUserGroupRank(groupId, rankList, serverId, reqMsg.getIsEnd());
    }

    @Override
    public void sendData() {

    }
}
